<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>管理员审核活动</title>
    <link href="http://cdn.bootcss.com/twitter-bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
    <style type="text/css">
        table {
            font-family: verdana, arial, sans-serif;
            font-size: 20px;
            color: #333333;
            border-width: 1px;
            border-color: #999999;
            border-collapse: collapse;
            margin: 0 auto;
            margin-top: 150px;
        }

        table th {
            background-color: #c3dde0;
            border-width: 1px;
            padding: 8px;
            border-style: solid;
            border-color: #a9c6c9;
        }

        table tr {
            background-color: #d4e3e5;
        }

        table td {
            border-width: 1px;
            padding: 8px;
            border-style: solid;
            border-color: #a9c6c9;
            white-space: nowrap;
        }

        .examine {
            position: relative;
            left: 50%;
            top: 100px;
            text-align: center;
            margin-left: -450px;

        }

        p {
            text-align: center;
            font-size: 30px;
            font-weight: bold;
        }
    </style>
</head>
<body>
<form action="" method="post" id="examine">
    <table cellpadding="0">
        <tr>
            <a href="javascript:void(0)" class="examine btn btn-info btn-lg" onclick="returnFirst(this)">返回首页</a>
        </tr>
        <colgroup>
            <col width="10">
            <col width="55">
            <col width="20">
            <col width="15">
        </colgroup>
        <tr>
            <th width=50>序号</th>
            <th width=100>活动标题</th>
            <th width=200>活动开始时间</th>
            <th width=100>审核</th>
        </tr>
        <%int num = 1;%>
        <c:forEach var="activity" items="${activities}">

            <tr>
                <td align="center"><%=num++ %>
                </td>
                <td align="center">
                    <a href="/action-info.html?actionid=${activity.id}" target="_blank">${activity.title} </a>
                </td>
                <td align="center"><fmt:formatDate value="${activity.startTime}" pattern="yyyy年MM月dd日 HH:mm:ss"/></td>
                <td align="center ">
                    <a data-acid="${activity.id}" href="javascript:void(0)" class="pass btn btn-success btn-lg">通过</a>
                    <a href="javascript:void(0)" id="unPass" onclick="unPass(this,'${activity.id}')"
                       class="unpass btn btn-warning btn-lg">不通过</a>

                    <div class="rea" style="display: none">请输入不通过原因
                        <textarea name="comment" rows="2" cols="30"></textarea>不超过30字
                        <input class="btn-sub" type="button" value="提交"/>
                        <input type="button" value="取消" class="cancel"/>
                    </div>
                </td>

            </tr>
        </c:forEach>
    </table>
    <br>
    <c:if test="${curPage gt 1}">
        <a href="/admin/examine/list.do?page=${curPage-1}" class="btn btn-info btn-lg"
           style="position: relative;left: 50%; margin-left: -44px;">上一页</a>
    </c:if>
    <c:if test="${curPage lt totalPage}">
        <a href="/admin/examine/list.do?page=${curPage +1}" class="btn btn-info btn-lg"
           style="position: relative;left: 50%; margin-left: -44px;">下一页</a>
    </c:if>
    <c:if test="${totalPage gt 0}">
        <p style="text-align: center;">共${totalPage}页，当前第${curPage}页</p>
    </c:if>


</form>
</body>
</html>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script type="text/javascript">
    function reasonSubmit(id) {
        document.forms.examine.action = "/admin/examine.do?id=" + id + "&state=2";
        examine.submit();
    }

    function returnFirst(obj) {
        obj.href = "/admin/index.do";
    }
    $(".pass").click(function (e) {
        var me = this;
        $.ajax({
            type: "POST",
            url: "/admin/examine.do",
            data: {
                id: $(this).closest("td").find(".pass").data("acid"),
                state: 1
            },
            cache: false,
            success: function (data) {
                if (!data.ret) {
                    if (data.errcode === 0) {
                        alert(data.errmsg);
                        return false;
                    } else {
                        alert("审核失败");
                        return false;
                    }
                }
                if (data.data === "pass") {
                    $($(me)).closest("tr").remove();
                }

            },
            error: function (data) {

            }
        });
    });
    $(".unpass").click(function (e) {
        $(this).closest("td").find(".rea").show();
    });
    $(".cancel").click(function (e) {
        $(".rea").hide();
    });
    $(".btn-sub").click(function (e) {
        var me = this;
        $.ajax({
            type: "POST",
            url: "/admin/examine.do",
            data: {
                id: $(this).closest("td").find(".pass").data("acid"),
                state: 2,
                comment: $("textarea").val()
            },
            cache: false,
            success: function (data) {
                if (data.data === "pass") {
                    $($(me)).closest("tr").remove();
                }

                if (!data.ret) {
                    if (data.errcode === 0) {
                        alert(data.errmsg);
                        return false;
                    } else {
                        alert("审核失败");
                        return false;
                    }
                }

            },
            error: function (data) {

            }
        });
    });
</script>
